package com.api.gbhg.lbj.action;


import com.api.gbhg.lbj.dao.ReimbursementDao;
import com.api.gbhg.zengping.common.CommonDao;

import com.api.gbhg.zengping.dao.PropertyManagementCostDao;
import com.sap.db.util.StringUtil;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.conn.RecordSet;
import weaver.conn.RecordSetTrans;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;


/**
 * @author lbj
 * @version 1.0
 * @description: TODO 主表金额退回
 * @date 2021/3/11 14:57
 */
public class MainreturnAmountAction implements Action {
    private static final Logger logger = LoggerFactory.getLogger("gbhg");
    @Override
    public String execute(RequestInfo requestInfo) {
            //请求id
            String requestid = requestInfo.getRequestid();
            //获取表名
            String billTableName = requestInfo.getRequestManager().getBillTableName();
            String src = requestInfo.getRequestManager().getSrc();
            logger.info("主表退回释放预算冻结额度------:"+src+"..."+requestid);
            RecordSetTrans rst = new RecordSetTrans();
            rst.setAutoCommit(false);
            if (src.equals("reject")) {
                RecordSet rs = CommonDao.selectByRequestId(new RecordSet(), billTableName, requestid);
                if (rs.next()) {
                    Map<String, String> list = new HashMap<>();
                    String lcjlid = rs.getString("ysxm");
                    String bmjjzcfl = rs.getString("bmjjzcfl");
                    String zcqd = rs.getString("zcqd");
                    String ysly = rs.getString("ysly");
                    String fzysrfl = Util.null2String(rs.getString("fzysrfl"));
                    String xzkmdm =  Util.null2String(rs.getString("xzkmdm"));
                    String bxje = rs.getString("bxje");
                    String tybxje = rs.getString("tybxje");
                    String cxje = rs.getString("bccxjkje");
                    if (StringUtils.isBlank(cxje)){
                        cxje="0.00";
                    }
                    list.put("lcjlid", lcjlid);//预算项目
                    list.put("money", bxje);//申请报销金额
                    list.put("tybxje", tybxje);//同意报销金额
                    list.put("zcqd", zcqd);//支出渠道
                    list.put("ysly", ysly);//预算来源
                    list.put("fzysrfl", fzysrfl);//非中央收入分类
                    list.put("xzkmdm", xzkmdm);//选择科目代码
                    list.put("bmjjzcfl", bmjjzcfl);//部门经济支出分类
                    list.put("cxje", cxje);
                    ReimbursementDao rei = new ReimbursementDao();
                    boolean b = rei.queryMainJingfei(rst,list,false,1);
//                boolean j=true;
//                if (StringUtils.isNotBlank(xzkmdm)||StringUtils.isNotBlank(ysly)){
//                    j = rei.jingfeilaiyuandonjie2(list, true);
//                }
                    if (!b) {
                        rst.rollback();
                        logger.info("=====================退回错误=======================");
                        requestInfo.getRequestManager().setMessagecontent("退回失败");
                        requestInfo.getRequestManager().setMessageid("1");
                        return FAILURE_AND_CONTINUE;
                    }
                }
            }
        RecordSet del = new RecordSet();
        del.execute("delete from uf_bxsjjl where lcid="+requestid);
        rst.commit();
        return Action.SUCCESS;
    }

}
